"use client"; import { getSendCodeApi } from "@/api/user"; import ButtonOwn from "@/components/ButtonOwn"; import DomainFooter from "@/components/DomainFooter"; import HeaderBack from "@/components/HeaderBack"; import { useRouter } from "@/i18n"; import { useTranslations } from "next-intl"; import { useSearchParams } from "next/navigation"; import { FC, useEffect, useRef, useState } from "react"; import "./page.scss"; interface Props {} const ResetPhone: FC = () => { const t = useTranslations("VerificationPage"); const router: any = useRouter(); let [code, setCode] = useState(""); const changeCode = (e: { target: { value: any } }) => { setCode(e.target.value.replace(/[^0-9]/g, "")); }; let searchParams = useSearchParams(); let user_phone = searchParams.get("userPhone"); const sendCodeRequest = () => { if (!user_phone) return; getSendCodeApi({ user_phone }).then((res) => { if (res.code == 200) { setTime(60); setIsNote(true); } }); }; useEffect(() => { sendCodeRequest(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); let [isNote, setIsNote] = useState(true); let [time, setTime] = useState(60); let timeRef: any = useRef(); useEffect(() => { if (time && time != 0) { timeRef.current = setTimeout(() => { setTime((time) => time - 1); }, 1000); } else { setIsNote(false); } return () => { timeRef.current && clearInterval(timeRef.current); }; }, [time]); const sendCodeFun = () => { if (isNote) return; sendCodeRequest(); }; const goPage = () => { if (!code || code.length < 6) return; router.push(`/confirmPassword?userPhone=${user_phone}&code=${code}`); }; return (

{t("h2")}

{t("h3")} {user_phone}
{isNote ? `${time}s` : t("Envie")}
{t("Completar")}
); }; export default ResetPhone;